package dao_manager;

import java.util.List;

import org.hibernate.Query;

import dao_hibernate.GenericDAOImpl;
import dao_hibernate.GenericDao;
import dao_hibernate.HibernateUtil;
import beans.FileMeta;

public class FileMetaManagerImpl implements FileMetaManager {
    
    private GenericDao<FileMeta, Long> fileMeta=new GenericDAOImpl<FileMeta, Long>() {};

    @Override
    public void saveFileMeta( FileMeta fM ) {
        
        try {
            HibernateUtil.beginTransaction();
            fileMeta.save(fM);
            HibernateUtil.commitTransaction();
        } catch (Exception ex) {
            ex.printStackTrace();
            HibernateUtil.rollback();
        }
        HibernateUtil.closing();
        
    }

    @Override
    public List<FileMeta> getFileMeta( Long ClientID ) {
            List<FileMeta> l=null;
        try {
            HibernateUtil.beginTransaction();
            Query query = HibernateUtil.getSession().getNamedQuery("getFileMeta");
            query.setLong( 0, ClientID );
            l= fileMeta.findMany( query );
            HibernateUtil.commitTransaction();
        } catch (Exception ex) {
            ex.printStackTrace();
            HibernateUtil.rollback();
        }
        HibernateUtil.closing();
        return l;
    }

}
